package com.cq.hd.order.mq.provider;

import com.cq.hd.common.constant.Constant;
import com.cq.hd.common.constant.RabbitMqConstant;
import com.cq.hd.common.utils.GenerateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Component
@Slf4j
public class OrderDelayMsgProvider {

    // 15分钟
    public final static Integer DELAYED_SECOND = Constant.ORDER_DELAY_TIME * 60 * 1000;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(String orderNo) {
        Map<String, Object> map = new HashMap<>(2);
        map.put("messageId", GenerateUtil.getMsg("order-delay"));
        map.put("messageData", orderNo);
        log.info("发送订单延时消息：" + map.toString());

        rabbitTemplate.convertAndSend(RabbitMqConstant.DL_ORDER_EXCHANGE_DIRECT, RabbitMqConstant.DL_ORDER_ROUTING_KEY, map, message -> {
            message.getMessageProperties().setDelay(DELAYED_SECOND);
            return message;
        });
    }

}
